const { Op } = require("sequelize");
const Employees = require("../database/model-employee");
const employee = async (ctx) => {
  const { search } = ctx.request.query || {};
  let res;
  if (search) {
    res = await Employees.findAll({
      where: {
        [Op.or]: [
          { name: { [Op.like]: `%${search}%` } },
          { code: { [Op.like]: `%${search}%` } },
        ]
      },
    });
  } else {
    res = await Employees.findAll();
  }
  ctx.success({
    data: res,
  });
};

employee.query = {
  search: 'name | code'
}

module.exports = employee;
